package com.eedi.framework.oauth2.dal.mapper;

import com.eedi.framework.common.enums.UserTypeEnum;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.oauth2.dal.dataobject.SysOAuth2ApproveDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SysOAuth2ApproveMapper extends BaseMapperX<SysOAuth2ApproveDO> {

    default int update(SysOAuth2ApproveDO updateObj) {
        return update(updateObj, new LambdaQueryWrapperX<SysOAuth2ApproveDO>()
                .eq(SysOAuth2ApproveDO::getUserId, updateObj.getUserId())
                .eq(SysOAuth2ApproveDO::getUserType, updateObj.getUserType())
                .eq(SysOAuth2ApproveDO::getSysOauth2ClientId, updateObj.getSysOauth2ClientId())
                .eq(SysOAuth2ApproveDO::getScope, updateObj.getScope()));
    }

    default List<SysOAuth2ApproveDO> selectListByUserIdAndUserTypeAndClientId(String userId, UserTypeEnum userType, String clientId) {
        return selectList(new LambdaQueryWrapperX<SysOAuth2ApproveDO>()
                .eq(SysOAuth2ApproveDO::getUserId, userId)
                .eq(SysOAuth2ApproveDO::getUserType, userType)
                .eq(SysOAuth2ApproveDO::getSysOauth2ClientId, clientId));
    }

}
